package main

import (
	"github.com/gin-gonic/gin"
	"hcy-api/lib/middleware"
	"idp/api"
)

func RegisterRouter(r *gin.RouterGroup) {
	clientRouter(r) // 客户端的路由
	branchRouter(r) // 分支机构路由
	taskRouter(r)   // 任务路由
	mapRouter(r)    // 矢量地图路由
}

func branchRouter(r *gin.RouterGroup) {
	sub := r.Group("branch")
	sub.Use(middleware.GinAuthorizationMiddleAware())
	sub.GET("page", api.BranchApi.Page)
	sub.GET("list", api.BranchApi.List)
	sub.POST("add", api.BranchApi.Create)
	sub.PUT("update", api.BranchApi.Update)
	sub.DELETE("/:id", api.BranchApi.Delete)
	sub.PUT("bindUser", api.BranchApi.BindUser)
	sub.GET("boundUser/:id", api.BranchApi.BoundUserId)
	sub.POST("pic", api.FileApi.UploadPic)

}

func clientRouter(r *gin.RouterGroup) {
	sub := r.Group("client")
	sub.Use(middleware.GinAuthorizationMiddleAware())
	sub.GET("page", api.ClientApi.Page)
	sub.GET("list", api.ClientApi.List)
	sub.GET("log", api.ClientApi.GetDetail)
	sub.GET("freeList", api.ClientApi.FreeList)
	sub.POST("distribution", api.ClientApi.Distribution)
	sub.POST("execPlugin", api.ClientApi.ExecPlugin)
}

func taskRouter(r *gin.RouterGroup) {
	sub := r.Group("task")
	sub.Use(middleware.GinAuthorizationMiddleAware())
	sub.POST("add", api.TaskApi.Add)                    // 添加
	sub.GET("page", api.TaskApi.Page)                   // 分页
	sub.PUT("/:id", api.TaskApi.StopTask)               // 停止任务
	sub.GET("countResult/:id", api.TaskApi.CountResult) // 获取任务统计结果

}

func mapRouter(r *gin.RouterGroup) {
	sub := r.Group("map")
	sub.Use(middleware.GinAuthorizationMiddleAware())
	// 获取当前用户的城市编码，该数据会直接影响json地图渲染
	sub.GET("cityCode", api.BranchApi.GetCityCode)
	// 保存办公室设计图标记点信息
	sub.POST("officePoint", api.BranchApi.SaveOfficePoint)
	sub.GET("officePoint/:id", api.BranchApi.GetOfficePoint)

}
